//
//  BHCirclePublishImageAddCell.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/12.
//

import UIKit
import Photos
class BHCirclePublishImageAddCell: UICollectionViewCell {

    var deleteChoseImageBlock:(() -> Void)?
    
    
    @IBOutlet weak var imageBtn: UIButton!
    
    @IBOutlet weak var delBtn: UIButton!
    
    var model: BHImageOrVideoModel? {
        didSet {
            self.imageBtn.isHidden = false
            self.delBtn.isHidden = model == nil
            if model == nil {
                self.imageBtn.setImage(UIImage.init(named: "bh_circle_image_add_place"), for: .normal)
                self.imageBtn.setBackgroundImage(nil, for: .normal)
            }else {
                if model?.sourceType == 0 {
                    self.imageBtn.setImage(nil, for: .normal)
                }else {
                    self.imageBtn.setImage(UIImage.init(named: "bh_common_video_pause"), for: .normal)
                }

                model?.transAssetToImage(handler: { (image) in
                    self.imageBtn.setBackgroundImage(image, for: .normal)
                })
            
            }
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
       
        self.imageBtn.addLayerCorner(1, 0.5, .color_cccccc)
        self.imageBtn.imageView?.contentMode = .scaleAspectFill
        self.delBtn.addBtnAction(action: {[weak self] (_) in
            self?.deleteChoseImageBlock?()
        }, for: .touchUpInside)
    }

}
